// pages/enterprise/mine/mine.js
import {
    ajaxPost,
    showToast
} from '../../../utils/util'
let app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        companySource: {},
        footerSource: [{
                title: '选选',
                url: '/pages/enterprise/list/list',
                img: '/images/icon_footer_icon1.png',
                imgSet: '/images/icon_footer_icon1_set.png',
                select: false
            },
            {
                title: '招聘会',
                url: '/pages/enterprise/home/home',
                img: '/images/icon_footer_icon2.png',
                imgSet: '/images/icon_footer_icon2_set.png',
                select: false
            },
            {
                title: '我的',
                url: '',
                img: '/images/icon_footer_icon3.png',
                imgSet: '/images/icon_footer_icon3_set.png',
                select: true
            },
        ],
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let data = {
            token: wx.getStorageSync("token"),
        }
        ajaxPost("/company/myCompanyInfo", data, (res) => {
            if (res.code == 0) {
                app.globalData.companState = res.data.company_info.is_authentication
                this.setData({
                    companySource: res.data.company_info
                })
            } else {
                showToast('text', res.msg);
            }
        });
    },
    /**
     * 企业未认证跳转
     */
    authentication() {
        if (this.data.companySource.is_authentication == 0) {
            wx.navigateTo({
                url: `/pages/web/web?url=${app.globalData.WEBURL}/h5/index/weiRenZhengJianLi`
            });
        }
    },
    /**
     * 身份切换
     */
    switch () {
        let data = {
            token: wx.getStorageSync("token"),
            usertype: 3,
        }
        ajaxPost("/authuser/usertype", data, function (res) {
            if (res.code == 0) {
                wx.redirectTo({
                    url: "/pages/student/home/home"
                });
            } else {
                showToast('text', res.msg);
            }
        });
    },
    /**
     * 使用教程跳转
     */
    course() {
        wx.navigateTo({
            url: `/pages/web/web?url=${app.globalData.WEBURL}/h5/index/shiYongJiaoCheng`
        });
    },
    /**
     * 扫描简历
     */
    openCode() {
        wx.scanCode({
            onlyFromCamera: true,
            success(res) {
                wx.navigateTo({
                    url: res.path
                });
            }
        })
    },
})